package com.ruoyi.common.page;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;

/**
 * 通用 分页参数响应体
 * @author dingwei
 */
@Data
public class PageParamResponse implements Serializable {

    @ApiModelProperty("数据总数")
    protected Long totalCount;

    @ApiModelProperty("当前页码")
    protected Long pageNum;

    @ApiModelProperty("每页数据数量")
    protected Long pageSize;

    @ApiModelProperty("总页数")
    protected Long totalPage;

    @ApiModelProperty("是否有上一页")
    protected Boolean hasPrevious;

    @ApiModelProperty("是否有下一页")
    protected Boolean hasNext;

    /**
     * 判断分页参数响应初始值
     * @param t
     * @param e
     * @param <T>
     * @param <E>
     * @return
     */
    public static <T extends PageParamResponse, E extends PageParamRequest> T defaultParam(T t, E e){
        if (t.totalCount == null || t.totalCount <= 0) {
            t.totalCount = 0L;
        }
        if (t.pageNum == null || t.pageNum <= 0) {
            t.pageNum = e.getPageNum();
        }
        if (t.pageSize == null || t.pageSize <= 0) {
            t.pageSize = e.getPageSize();
        }
        return t;
    }
}
